﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MayhemCore;
using MayhemWpf;
using System.IO;
using MayhemWpf.UserControls;
using DefaultModules.Wpf;
using System.Runtime.InteropServices;
using System.Windows.Input;
using System.Windows.Forms;
using MayhemWpf.ModuleTypes;

namespace KeyModule{

    [DataContract]

    [MayhemModule("Key Press", "Choose which key gets pressed   ")]

    public class KeyPress : ReactionBase, IWpfConfigurable
    {
        [DataMember]
        private string message;

        protected override void OnLoadDefaults()
        {
            message = "";
        }

        public override void Perform()
        {
            switch (message)
            {
                /* Directionals */
                case "left":
                    SendKeys.SendWait("{LEFT}");
                    break;
                case "right":
                    SendKeys.SendWait("{RIGHT}");
                    break;
                case "up":
                    SendKeys.SendWait("{UP}");
                    break;
                case "down":
                    SendKeys.SendWait("{DOWN}");
                    break;

                /* Keyboard Commands */
                case "space":
                    SendKeys.SendWait(" ");
                    break;
                case "windows":
                    SendKeys.SendWait("^({ESC})");
                    break;
                case "enter":
                    SendKeys.SendWait("{ENTER}");
                    break;
                case "backspace":
                    SendKeys.SendWait("{BACKSPACE}");
                    break;
                case "delete":
                    SendKeys.SendWait("{DEL}");
                    break;
                case "capslock":
                    SendKeys.SendWait("CAPSLOCK");
                    break;
                case "end":
                    SendKeys.SendWait("{END}");
                    break;
                case "home":
                    SendKeys.SendWait("{HOME}");
                    break;
                case "insert":
                    SendKeys.SendWait("{INSERT}");
                    break;
                case "pagedown":
                    SendKeys.SendWait("{PGDN}");
                    break;
                case "pageup":
                    SendKeys.SendWait("{PGUP}");
                    break;
                case "printscreen":
                    SendKeys.SendWait("{PRTSC}");
                    break;
                case "esc":
                    SendKeys.SendWait("{ESC}");
                    break;

                /* F keys */
                case "f1":
                    SendKeys.SendWait("{F1}");
                    break;
                case "f2":
                    SendKeys.SendWait("{F2}");
                    break;
                case "f3":
                    SendKeys.SendWait("{F3}");
                    break;
                case "f4":
                    SendKeys.SendWait("{F4}");
                    break;
                case "f5":
                    SendKeys.SendWait("{F5}");
                    break;
                case "f6":
                    SendKeys.SendWait("{F6}");
                    break;
                case "f7":
                    SendKeys.SendWait("{F7}");
                    break;
                case "f8":
                    SendKeys.SendWait("{F8}");
                    break;
                case "f9":
                    SendKeys.SendWait("{F9}");
                    break;
                case "f10":
                    SendKeys.SendWait("{F10}");
                    break;
                case "f11":
                    SendKeys.SendWait("{F11}");
                    break;
                case "f12":
                    SendKeys.SendWait("{F12}");
                    break;

                /* Calculator commands */
                case "add":
                    SendKeys.SendWait("{ADD}");
                    break;
                case "subtract":
                    SendKeys.SendWait("{SUBTRACT}");
                    break;
                case "multiply":
                    SendKeys.SendWait("{MULTIPLY}");
                    break;
                case "divide":
                    SendKeys.SendWait("{DIVIDE}");
                    break;

                /* Control Commands */
                case "copy":
                    SendKeys.SendWait("^(c)");
                    break;
                case "paste":
                    SendKeys.SendWait("^(v)");
                    break;
                case "selectall":
                    SendKeys.SendWait("^(a)");
                    break;
                case "cut":
                    SendKeys.SendWait("^(x)");
                    break;
                case "undo":
                    SendKeys.SendWait("^(z)");
                    break;
                case "redo":
                    SendKeys.SendWait("^(y)");
                    break;
                case "save":
                    SendKeys.SendWait("^(s)");
                    break;
                case "open":
                    SendKeys.SendWait("^(o)");
                    break;
                case "play":
                    SendKeys.SendWait("^(p)");
                    break;
                case "pause":
                    SendKeys.SendWait("^(p)");
                    break;
                case "previous":
                    SendKeys.SendWait("^(b)");
                    break;
                case "next":
                    SendKeys.SendWait("^(b)");
                    break;

                //For purposes of opening
                case "multitab":
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");
                    break;
                case "opento":
                    SendKeys.SendWait("^(o)");
                    System.Threading.Thread.Sleep(500);
                    goto case "multitab";

                /* Alt Commands */
                case "alt":
                    SendKeys.SendWait("%()");
                    break;
                case "alttab":
                    SendKeys.SendWait("%({TAB})");
                    break;
                case "alttab2":
                    SendKeys.SendWait("%({TAB 2})");
                    break;
                case "altf4":
                    SendKeys.SendWait("%({F4})");
                    break;
                case "fullscreen":
                    SendKeys.SendWait("%({ENTER})");
                    break;

                /* LETTERS */
                case "a":
                    SendKeys.SendWait("a");
                    break;
                case "b":
                    SendKeys.SendWait("b");
                    break;
                case "c":
                    SendKeys.SendWait("c");
                    break;
                case "d":
                    SendKeys.SendWait("d");
                    break;
                case "e":
                    SendKeys.SendWait("e");
                    break;
                case "f":
                    SendKeys.SendWait("f");
                    break;
                case "g":
                    SendKeys.SendWait("g");
                    break;
                case "h":
                    SendKeys.SendWait("h");
                    break;
                case "i":
                    SendKeys.SendWait("i");
                    break;
                case "j":
                    SendKeys.SendWait("j");
                    break;
                case "k":
                    SendKeys.SendWait("k");
                    break;
                case "l":
                    SendKeys.SendWait("l");
                    break;
                case "m":
                    SendKeys.SendWait("m");
                    break;
                case "n":
                    SendKeys.SendWait("n");
                    break;
                case "o":
                    SendKeys.SendWait("o");
                    break;
                case "p":
                    SendKeys.SendWait("p");
                    break;
                case "q":
                    SendKeys.SendWait("q");
                    break;
                case "r":
                    SendKeys.SendWait("r");
                    break;
                case "s":
                    SendKeys.SendWait("s");
                    break;
                case "t":
                    SendKeys.SendWait("t");
                    break;
                case "u":
                    SendKeys.SendWait("u");
                    break;
                case "v":
                    SendKeys.SendWait("v");
                    break;
                case "w":
                    SendKeys.SendWait("w");
                    break;
                case "x":
                    SendKeys.SendWait("x");
                    break;
                case "y":
                    SendKeys.SendWait("y");
                    break;
                case "z":
                    SendKeys.SendWait("z");
                    break;

                /* NUMBERS */
                case "0":
                    SendKeys.SendWait("0");
                    break;
                case "1":
                    SendKeys.SendWait("1");
                    break;
                case "2":
                    SendKeys.SendWait("2");
                    break;
                case "3":
                    SendKeys.SendWait("3");
                    break;
                case "4":
                    SendKeys.SendWait("4");
                    break;
                case "5":
                    SendKeys.SendWait("5");
                    break;
                case "6":
                    SendKeys.SendWait("6");
                    break;
                case "7":
                    SendKeys.SendWait("7");
                    break;
                case "8":
                    SendKeys.SendWait("8");
                    break;
                case "9":
                    SendKeys.SendWait("9");
                    break;

                default: 
                    MessageBox.Show("WRONG INPUT");
                    break;
            }
        }

        public WpfConfiguration ConfigurationControl
        {
            get
            {
                return new KeyPressedControl(message);
            }
        }

        public void OnSaved(WpfConfiguration configurationControl)
        {
            message = ((KeyPressedControl)configurationControl).Message;
        }

        public string GetConfigString()
        {
            return "Set key to " + message;
           // return string.Format("Set the volume to {0}%", level);
        }
    }
}

